var res,
    num = new Array(),
    rate;

$.ajaxSettings.async = false;
function getData(){
    $.get('./php/show.php',function(data){
        res = JSON.parse(data);
        rate = Math.ceil(num.length / res.name.length * 100);
        let oHeight = res.name.length * 4.3;
        $('.chart').css('height',`${oHeight < 95 ? oHeight : 95}vh`);
    });
}
getData();
$('#refresh').click(function(){
    location.reload();
})

$('#reset').click(function(){
    $.get('./php/reset.php',function(data){
        alert('重置完成，可以开始新一轮测试！');
        location.reload();
    });
});

require.config({
    paths: {
        echarts: 'https://echarts.baidu.com/build/dist'
    }
});

require(
    [
        'echarts',
        'echarts/chart/bar',
        'echarts/chart/line',
    ],
    function(ec){
        var myChart = ec.init(document.getElementById('chart_bar'));

        var option = {
            tooltip : {
                show: true,
                trigger: 'axis'
            },
            calculable : true,
            legend: {
                data: ['耗时','分数'],
            },
            xAxis: [
                {
                    type: 'value',
                    name : '耗时',
                    axisLabel : {
                        formatter: "{value} 秒"
                    }
                }
            ],
            yAxis: [
                {
                    type: 'category',
                    position: 'bottom',
                    data : res.name,
                },
            ],
            series: [
                {
                    name : '耗时',
                    type : 'bar',
                    data : res.time,
                },
                {
                    name: '分数',
                    type: 'bar',
                    data: res.score
                }
            ]
        };
        myChart.setOption(option);
    }
)
